package com.grm.workflow.controller;

import com.grm.common.entity.PageResult;
import com.grm.common.entity.Result;
import com.grm.workflow.request.model.WfModelQueryParam;
import com.grm.workflow.request.process.WfProcessQueryParam;
import com.grm.workflow.response.WfModelResponse;
import com.grm.workflow.response.WfProcessResponse;
import com.grm.workflow.service.WfModelService;
import com.grm.workflow.service.WfProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 流程管理
 *
 * @author gaorimao
 * @since 2024-08-16
 */
@RestController
@RequestMapping("/workflow/process")
public class WfProcessController {
    @Autowired
    private WfProcessService wfProcessService;

    @PostMapping("/list")
    public Result querySelective(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestBody WfProcessQueryParam queryParam) {
        // 开启分页
        PageResult<WfProcessResponse> pageResult = wfProcessService.querySelective(pageNum,pageSize,queryParam);
        return Result.success(pageResult.getData(),pageResult.getTotal());
    }

    // 启动流程实例
    @PostMapping("/start/{processDefId}")
    public Result start(@PathVariable(value = "processDefId") String processDefId, @RequestBody Map<String, Object> variables) {
        wfProcessService.start(processDefId,variables);
        return Result.success();
    }
}
